package com.gpStudy.design.observer;

import java.util.Observable;
import java.util.Observer;

public class OberverTest {

    public static void main(String[] args) {
//        observe_v1();
        observe_v2();
    }

    public static void observe_v2(){

        GPer gPer = GPer.getInstance();

        Observer observer = new Observer() {
            @Override
            public void update(Observable o, Object arg) {
                //1.找到这个人的websocket
                //2.写入待办
                System.out.println("收到一条待办");
            }
        };

        gPer.addObserver(observer);

        Question question = new Question();
        question.setUserName("小明");
        question.setContent("观察者模式除了jdk的实现还有其他的实现方式吗？");

        gPer.publicQuestion(question);

    }

    public static void observe_v1(){

        GPer gPer = GPer.getInstance();
        Question question = new Question();
        question.setUserName("小明");
        question.setContent("观察者模式除了jdk的实现还有其他的实现方式吗？");

        Teachet t = new Teachet("Tom");
        Teachet t1 = new Teachet("mic");
        gPer.addObserver(t);

        gPer.addObserver(t1);

        gPer.publicQuestion(question);

    }
}
